package com.honetooyoung.javaW.welcomePage;


import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Map;

public class welcomeServlet extends HttpServlet {

//    @Override
//    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        response.setContentType("text/html");
//        PrintWriter out = response.getWriter();
//        out.print("<h1>Get请求已发送！<h>");
//    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获得参数Map集合
        // key—>name;
        // value—>value;
        Map<String, String[]> parameterMap = request.getParameterMap();
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        for (String key : parameterMap.keySet()) {
            for(String value:parameterMap.get(key)){
                out.print(value+"<br>");
            }
        }
        out.print("<hr>");
        //getParameterNames(),获得参数name的集合
        //request.getParameter,获得name下的第一个value
        Enumeration<String> parameterNames = request.getParameterNames();
        while(parameterNames.hasMoreElements()){
            out.print(request.getParameter( parameterNames.nextElement())+"<br>");
        }

       // for (String parameterValue : request.getParameterValues(name)) {
        //通过name获得value数组
        //}

        /*
        * 注意:放在WEB-INF目录下的资源是受保护的。在浏览器上不能够通过路径直接访问
        * 所以像HTML、CSS、JS、image等静态资源一定要放到WEB-INF目录之外。
         */

    }
}
